#include "02playscene.h"
#include<QMovie>

Playscene::Playscene(QWidget *parent) : QMainWindow(parent)
{
   initSence();

}
//初始化场景
void Playscene::initSence()
{


    //战机血条图片
    pix_blood.load(":/rec.image/My_Blood.png");
    //战机蓝条图片
    pix_bule.load(":/rec.image/Blue.png");

    //设置窗口固定尺寸
    setFixedSize(GAME_WIDTH,GAME_HEIGHT);
    //设置标题
    setWindowTitle(GAME_TITLE);
    //设置标题图片
    setWindowIcon(QIcon(":/rec.image/Icon.png"));

    //僚机位置
    if(m_Wing_left.is_on)
    {
        m_Wing_left.m_x=m_hero.m_x-70;
        m_Wing_left.m_y=m_hero.m_y+20;
    }
    if(m_Wing_right.is_on)
    {
        m_Wing_right.m_x=m_hero.m_x+140;
        m_Wing_right.m_y=m_hero.m_y+20;
    }
    //定时器设置
    m_timer.setInterval(GAME_RATE);

    //开始游戏
    playGame();

    //游戏结束
    overlable=new QLabel;
    QPixmap temp;
    temp.load(":/rec.image/gameover.png");
    overlable->setGeometry(0,0,temp.width(),temp.height());;
    overlable->setPixmap(temp);
    overlable->setParent(this);
    overlable->move((this->width()-temp.width())*0.5,(-temp.height()));

    //警告
    warnlabel=new QLabel;
    QPixmap pix1;
    pix1.load(":/rec.image/warnning.png");
    warnlabel->setGeometry(0,0,pix1.width(),pix1.height());
    warnlabel->setPixmap(pix1);
    warnlabel->setParent(this);
    warnlabel->move((this->width()-pix1.width())*0.5,(-pix1.height()));


    //返回按钮
    back_btn=new QPushButton(this);//设置所属场景
   back_btn->setFixedSize(50,50);//设置固定大小
    back_btn->move(GAME_WIDTH-50,0);//设置位置
    back_btn->setIcon(QIcon(":/rec.image/7d3fdb1f21fc44e0897c5ce2b5990410.png"));
    back_btn->setIconSize(QSize(50,50));
    //重新开始按钮

    againbtn=new QPushButton(this);
    againbtn->setFixedSize(50,50);
    againbtn->move(GAME_WIDTH-50,70);
    againbtn->setIcon(QIcon(":/rec.image/again.png"));
    againbtn->setIconSize(QSize(50,50));
    //技能按钮
    big_btn=new QPushButton(this);
    big_btn->setFixedSize(80,80);
    big_btn->move(GAME_WIDTH-80,550);
    big_btn->setIcon(QIcon(":/rec.image/Big.png"));
    big_btn->setIconSize(QSize(80,80));
    //点击返回按钮
    connect(back_btn,&QPushButton::clicked,[=](){
        //发送返回信号
        emit(returnmain());
        //重置子弹数量
        this->m_hero.AddNum=1;
        //重置分数
        this->num=0;
        score->display(num);

        //重置金币
        m_gold_num=0;
        Gold->display(m_gold_num);
        for(int i=0;i<GOLD_NUM;i++)
        {
            m_golds[i].m_Free=1;
        }
        //重置敌机状态
        for(int i=0;i<ENEMY01_NUM;i++)
        {
            m_Enemy01s[i].m_Free=1;
            m_Enemy01s[i].m_Blood=ENEMY01_BLOOD;
            //重置敌机子弹
            for(int j=0;j<ENEMY01_BULLET_NUM;j++)
            {
                m_Enemy01s[i].enemy_bullet01s[j].m_Free=1;
            }
        }

        //重置boss状态
        m_Boss01.m_Free=1;
        m_Boss01.m_Blood=BOSS01_BLOOD;
        for(int i=0;i<BOSS01_BULLET_NUM;i++)
        {
            m_Boss01.Boss_Bullet01s[i].m_Free=1;
            m_Boss01.Boss_Bullet02s[i].m_Free=1;
            m_Boss01.Boss_Bullet03s[i].m_Free=1;
            m_Boss01.Boss_Bullet04s[i].m_Free=1;
        }
        //重置战机状态
        m_hero.m_Hero_Blood=m_blood_num;
        m_hero.m_HERO_Blue=m_blue_num;
        is_big=0;
        //初始化飞机坐标
        m_hero. m_x=(GAME_WIDTH-m_hero. m_Plane.width())*0.5;
        m_hero. m_y=(GAME_HEIGHT-m_hero.m_Plane.height());
        //初始化边框
        m_hero.m_Rect.moveTo(m_hero.m_x+50,m_hero.m_y+5);
        overlable->move((this->width()-temp.width())*0.5,(-temp.height()));
        //重置各类辅助图标
        m_UpAdds.m_Free=1;
        m_BackBloods.m_Free=1;
        m_Defends.m_Free=1;
        m_hero.m_shield_free=1;

        //敌机三
        for(int i=0;i<ENEMY03_NUM;i++)
        {
            m_Enemy03s[i].m_emeny.load(ENEMY03_PATH);
            m_Enemy03s[i].m_Blood=ENEMY03_BLOOD;
            m_Enemy03s[i].m_Free=1;
        }

        //僚机位置
        m_Wing_left.m_x=m_hero.m_x-60;
        m_Wing_left.m_y=m_hero.m_y+20;
        m_Wing_right.m_x=m_hero.m_x+130;
        m_Wing_right.m_y=m_hero.m_y+20;
        //僚机状态
        m_Wing_left.is_on=0;
        m_Wing_right.is_on=0;

        //音效暂停
        back_music->stop();

        //按钮音效
        btn_music->play();




    });
    //点击重新开始按钮
    connect(againbtn,&QPushButton::clicked,[=](){
        //重新开始
        this->m_timer.start();
        //隐藏失败图片
        this-> overlable->move((this->width()-temp.width())*0.5,(-temp.height()));
        //重置子弹数量
        this->m_hero.AddNum=1;
        //重置分数
        this->num=0;
        score->display(num);

        //重置金币
        m_gold_num=0;
        Gold->display(m_gold_num);
        for(int i=0;i<GOLD_NUM;i++)
        {
            m_golds[i].m_Free=1;
        }
        //重置敌机状态
        for(int i=0;i<ENEMY01_NUM;i++)
        {
            m_Enemy01s[i].m_Free=1;
            m_Enemy01s[i].m_Blood=ENEMY01_BLOOD;
            //重置敌机子弹
            for(int j=0;j<ENEMY01_BULLET_NUM;j++)
            {
                m_Enemy01s[i].enemy_bullet01s[j].m_Free=1;
            }
        }
        //重置boss状态
        m_Boss01.m_Free=1;
        m_Boss01.m_Blood=BOSS01_BLOOD;
        for(int i=0;i<BOSS01_BULLET_NUM;i++)
        {
            m_Boss01.Boss_Bullet01s[i].m_Free=1;
            m_Boss01.Boss_Bullet02s[i].m_Free=1;
            m_Boss01.Boss_Bullet03s[i].m_Free=1;
            m_Boss01.Boss_Bullet04s[i].m_Free=1;
        }

        //重置战机状态
        m_hero.m_Hero_Blood=m_blood_num;
         m_hero.m_HERO_Blue=m_blue_num;
         is_big=0;
        //初始化飞机坐标
        m_hero. m_x=(GAME_WIDTH-m_hero. m_Plane.width())*0.5;
        m_hero. m_y=(GAME_HEIGHT-m_hero.m_Plane.height());
        //初始化边框
        m_hero.m_Rect.moveTo(m_hero.m_x+50,m_hero.m_y+5);
        overlable->move((this->width()-temp.width())*0.5,(-temp.height()));
        //重置各类辅助图标
        m_UpAdds.m_Free=1;
        m_BackBloods.m_Free=1;
        m_Defends.m_Free=1;
        m_hero.m_shield_free=1;

        //敌机三
        for(int i=0;i<ENEMY03_NUM;i++)
        {
            m_Enemy03s[i].m_emeny.load(ENEMY03_PATH);
            m_Enemy03s[i].m_Blood=ENEMY03_BLOOD;
            m_Enemy03s[i].m_Free=1;
        }
        //僚机位置
        m_Wing_left.m_x=m_hero.m_x-60;
        m_Wing_left.m_y=m_hero.m_y+20;
        m_Wing_right.m_x=m_hero.m_x+130;
        m_Wing_right.m_y=m_hero.m_y+20;
        //音效重新播放
        back_music->stop();
        back_music->play();

        //按钮音效
        btn_music->play();




    });

    //点击技能按钮
    connect(big_btn,&QPushButton::clicked,[=](){
        emit(release_big());
    });

    connect(this,&Playscene::release_big,[=](){
        if(is_big==0)
        {
            if(m_hero.m_HERO_Blue>0)
            {
                is_big=1;
                //蓝减少30
                m_hero.m_HERO_Blue-=50;
                //持续五秒
                QTimer::singleShot(5000,[=](){
                    is_big=0;
                });
            }
        }
    });

    //初始化升级图片出场间隔
    m_UpAdd_Recorder=0;

    //初始化敌机一出场间隔
    m_Enemy01_Recorder=0;


    //随机数种子
    srand((unsigned int )time(NULL));


    //敌机三
    for(int i=0;i<ENEMY03_NUM;i++)
    {
        m_Enemy03s[i].m_emeny.load(ENEMY03_PATH);
        m_Enemy03s[i].m_Blood=ENEMY03_BLOOD;
        m_Enemy03s[i].m_Speed=ENEMY03_SPEED;
    }

    //得分记录
    score=new QLCDNumber;
    score->setParent(this);
     //设置字体
    score->setDecMode();

    //除去边框
    score->setFrameStyle(0);

    //位置
    score->move(10,10);
    //大小
    score->setFixedSize(QSize(200,50));

    //文字
    QLabel*lab=new QLabel(this);
    QPixmap pix;
    pix.load(":/rec.image/score.png");
    lab->setPixmap(pix);
    lab->show();
    lab->move(15,20);
    connect(this,&Playscene::explosion,[=](){
        this->num++;

        //显示分数
        score->display(num);
    });
    connect(this,&Playscene::boss_explosion,[=](){
        this->num+=10;
        //显示分数
        score->display(num);
    });


    //金币记录
    Gold=new QLCDNumber;
    Gold->setParent(this);
     //设置字体
    Gold->setDecMode();

    Gold->setFrameStyle(0);

    //位置
    Gold->move(10,100);
    //大小
    Gold->setFixedSize(QSize(180,70));

    //文字
    QLabel*lab_gold=new QLabel(this);
    QPixmap pix_gold;
    pix_gold.load(":/rec.image/golds.png");
    lab_gold->setFixedSize(87,70);
    lab_gold->setPixmap(pix_gold);
    lab_gold->show();
    lab_gold->move(15,100);
    //金币增加信号接收
    connect(this,&Playscene::gold_add,[=](){
        Gold->display(m_gold_num);
        m_gold_num++;
        gold_music->play();
    });


    //背景音乐
    back_music=new QSound(":/rec.image/Music_PlayBack.wav");
    back_music->setLoops(-1);
    //back_music->play();



    //初始化爆炸音效
    bomb_music01=new QSound(MUSIC_BOMB01);
    bomb_music02=new QSound(MUSIC_BOMB02);

    //按钮点击音效
    btn_music=new QSound(MUSIC_BTN);

    //吸收金币音效
    gold_music=new QSound(MUSIC_GOLD);

    //升级音效
    up_music=new QSound(MUSIC_UP);

    //警告音效
    alarm_music=new QSound(MUSIC_ALARM);

    //游戏结束
    over_music=new QSound(MUSIC_OVER);


}
//启动游戏
void Playscene::playGame()
{
   //m_timer.start();

   //监听定时器发出的信号
   connect(&m_timer,&QTimer::timeout,[=](){
       //更新地图元素
       updatePosition();
       //绘制
       update();

       //升级图标出现
       Upaddscence();
       //回血图标出场
       Back_Blood_scence();

       //护盾图标出场
       Defend_scence();

       //金币出场
       Gold_Scene();

       //敌机一出场
       Enemy01scence();
       //敌机3出场
       Enemy03scence();
       //碰撞检测
       collisionDetection();
       //boss出场
       this->Boss_scence();


   });

}
//更新所有元素坐标
void Playscene::updatePosition()
{


  m_map.mapPosition();

  //发射子弹
  m_hero.shoot();

  //是否放大招
  if(is_big)
  {
      m_hero.shoot2();
      m_hero.shoot3();
      m_hero.shoot4();
  }


  //发射僚机子弹
  m_Wing_left.shoot();
  m_Wing_right.shoot();
  //护盾出现
  m_hero.Shield();

  //计算所有非空闲子弹当前坐标
  for(int i=0;i<BULL_NUM;i++)
  {
      //如果非空闲，计算发射位置
      if(m_hero.AddNum==1)
      {
          if(m_hero.m_bullets1[i].m_Free==0)
          {
              m_hero.m_bullets1[i].updatePosition();

          }
      }
      else if(m_hero.AddNum==2)
      {
          if(m_hero.m_bullets1[i].m_Free==0)
          {
              m_hero.m_bullets1[i].updatePosition();
          }

          if(m_hero.m_bullets3[i].m_Free==0)
          {
              m_hero.m_bullets3[i].updatePosition();
          }
      }
      else if(m_hero.AddNum==3)
      {
          if(m_hero.m_bullets1[i].m_Free==0)
          {
              m_hero.m_bullets1[i].updatePosition();
          }


          if(m_hero.m_bullets2[i].m_Free==0)
          {
              m_hero.m_bullets2[i].updatePosition();
          }

          if(m_hero.m_bullets3[i].m_Free==0)
          {
              m_hero.m_bullets3[i].updatePosition();
          }
      }
  }
  //特殊子弹

  //特殊子弹的发射
  for(int i=0;i<BULL_NUM2;i++)
  {

      if(m_hero.m_special_bullets[i].m_Free==0)
      {
          m_hero.m_special_bullets[i].updatePosition2();
      }

  }

  //特殊子弹二
  for(int i=0;i<BULL_NUM3;i++)
  {

      if(m_hero.m_special_bullets2[i].m_Free==0)
      {
          m_hero.m_special_bullets2[i].updatePosition3();
      }

  }
  //特殊子弹三
  for(int i=0;i<BULL_NUM3;i++)
  {
      if(m_hero.m_special_bullets3[i].m_Free==0)
      {
          m_hero.m_special_bullets3[i].updatePosition4();
      }
  }



  //僚机子弹
  for(int i=0;i<WING_BULLET_NUM;i++)
  {
      if(m_Wing_left.m_bullets[i].m_Free==0)
      {
        m_Wing_left.m_bullets[i].updatePosition();
      }
  }
  for(int i=0;i<WING_BULLET_NUM;i++)
  {
      if(m_Wing_right.m_bullets[i].m_Free==0)
      {
        m_Wing_right.m_bullets[i].updatePosition();
      }
  }

  //升级图标出现,如果非空闲，计算发射位置
  if(m_UpAdds.m_Free==0)
  {
      m_UpAdds.updatePosition();
  }


  //回血图标出场,如果非空闲，计算发射位置
  if(m_BackBloods.m_Free==0)
  {
      m_BackBloods.updatePosition();
  }

  //护盾图标出场,如果非空闲，计算发射位置
  if(m_Defends.m_Free==0)
  {
      m_Defends.updatePosition();
  }


  //金币出场
  for(int i=0;i<GOLD_NUM;i++)
  {
      if(m_golds[i].m_Free==0)
      {
          m_golds[i].updatePosition();
      }
  }

  //敌机一出场
  for(int i=0;i<ENEMY01_NUM;i++)
  {
      //如果非空闲，计算出场位置
      if(m_Enemy01s[i].m_Free==0)
      {
          //发射子弹
          m_Enemy01s[i].shoot();
          m_Enemy01s[i].Enemt01_updatePosition();
          //敌机子弹更新坐标
          for(int j=0;j<ENEMY01_BULLET_NUM;j++)
          {
              //如果非空闲，计算发射位置
              if(m_Enemy01s[i].enemy_bullet01s[j].m_Free==0)
              {
                  m_Enemy01s[i].enemy_bullet01s[j].update_Enemy_Bullet_Position();
              }
          }
      }

  }


  //敌机3出场
  for(int i=0;i<ENEMY03_NUM;i++)
  {
      //如果非空闲，计算出场位置
      if(m_Enemy03s[i].m_Free==0)
      {
          //发射子弹

          m_Enemy03s[i].Enemt03_updatePosition();

      }

  }

  //boss出场
  if(m_Boss01.m_Free==0)
  {
      m_Boss01.Boss_updatePosition();
      //发射子弹
      m_Boss01.shoot();
      //发射子弹一
      for(int i=0;i<BOSS01_BULLET_NUM;i++)
      {
          if(m_Boss01.Boss_Bullet01s[i].m_Free==0)
          {
              m_Boss01.Boss_Bullet01s[i].update_Enemy_Bullet_Position();
          }
      }
      //发射子弹二
      for(int i=0;i<BOSS01_BULLET_NUM;i++)
      {
          if(m_Boss01.Boss_Bullet02s[i].m_Free==0)
          {
              m_Boss01.Boss_Bullet02s[i].update_Enemy_Bullet_Position();
          }
      }
      //发射子弹三
      for(int i=0;i<BOSS01_BULLET_NUM;i++)
      {
          if(m_Boss01.Boss_Bullet03s[i].m_Free==0)
          {
              m_Boss01.Boss_Bullet03s[i].update_Enemy_Bullet_Position();
          }
      }
      //发射子弹四
      for(int i=0;i<BOSS01_BULLET_NUM;i++)
      {
          if(m_Boss01.Boss_Bullet04s[i].m_Free==0)
          {
              m_Boss01.Boss_Bullet04s[i].update_Enemy_Bullet_Position();
          }
      }
  }

  //爆炸计算播放的图片
  for(int i=0;i<BOMB_NUM;i++)
  {
      if(m_bombs[i].m_Free==0)
      {
          m_bombs[i].update_Bomb_Info();
      }
  }
}
//绘制到屏幕中
void Playscene::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    //绘制地图
    painter.drawPixmap(0,m_map.m_map1_posY,m_map.m_map1);
    painter.drawPixmap(0,m_map.m_map2_posY,m_map.m_map2);

    //绘制飞机
    painter.drawPixmap(m_hero.m_x,m_hero.m_y,m_hero.m_Plane);
    //绘制僚机
    if(m_Wing_left.is_on)
    {
    painter.drawPixmap(m_Wing_left.m_x,m_Wing_left.m_y,m_Wing_left.m_Wing_Plane);
    }
    if(m_Wing_right.is_on)
    {
     painter.drawPixmap(m_Wing_right.m_x,m_Wing_right.m_y,m_Wing_right.m_Wing_Plane);
    }
    //绘制战机护盾
    if(m_hero.m_shield_free==0)
    {
        painter.drawPixmap(m_hero.m_Shield_x,m_hero.m_Shield_y,m_hero.m_Shield);
    }
    // 绘制战机血条
    painter.drawPixmap(400,0,pix_blood);
    //填充血条颜色
    QBrush bru(QColor(0,255,0));
    //放置血条
    painter.setBrush(bru);
    //计算血条比例
    float rate=1.0*m_hero.m_Hero_Blood/m_blood_num;
    if(rate<=0)
    {
        rate=0;
    }
    //绘制血条
    painter.drawRect(475,33,rate*(pix_blood.width()-85),24);

    //绘制战机蓝条
    painter.drawPixmap(460,80,pix_bule);
    //填充蓝条颜色
    QBrush bru2(QColor(0,0,255));
    //放置蓝条
    painter.setBrush(bru2);
    //计算蓝条比例
    float rate2=1.0*m_hero.m_HERO_Blue/m_blue_num;
    if(rate2<=0)
    {
        rate2=0;
    }
    //绘制蓝条
    painter.drawRect(495,85,rate2*(pix_bule.width()-40),15);


    //绘制子弹
    for(int i=0;i<BULL_NUM;i++)
    {
        //如果非空闲，开始绘制
        if(m_hero.AddNum==1)
        {
            if(m_hero.m_bullets1[i].m_Free==0)
            {              
               painter.drawPixmap(m_hero.m_bullets1[i].m_x,m_hero.m_bullets1[i].m_y,m_hero.m_bullets1[i].m_Bullet);
            }
        }
        else if(m_hero.AddNum==2)
        {
            if(m_hero.m_bullets1[i].m_Free==0)
            {
                painter.drawPixmap(m_hero.m_bullets1[i].m_x,m_hero.m_bullets1[i].m_y,m_hero.m_bullets1[i].m_Bullet);
            }

            if(m_hero.m_bullets3[i].m_Free==0)
            {
                painter.drawPixmap(m_hero.m_bullets3[i].m_x,m_hero.m_bullets3[i].m_y,m_hero.m_bullets3[i].m_Bullet);
            }
        }
        else if(m_hero.AddNum==3)
        {
            if(m_hero.m_bullets1[i].m_Free==0)
            {
                painter.drawPixmap(m_hero.m_bullets1[i].m_x,m_hero.m_bullets1[i].m_y,m_hero.m_bullets1[i].m_Bullet);
            }

            if(m_hero.m_bullets2[i].m_Free==0)
            {
                painter.drawPixmap(m_hero.m_bullets2[i].m_x,m_hero.m_bullets2[i].m_y,m_hero.m_bullets2[i].m_Bullet);
            }

            if(m_hero.m_bullets3[i].m_Free==0)
            {
                painter.drawPixmap(m_hero.m_bullets3[i].m_x,m_hero.m_bullets3[i].m_y,m_hero.m_bullets3[i].m_Bullet);
            }
        }

    }
    //绘制特殊子弹

    for(int i=0;i<BULL_NUM2;i++)
    {
            if(m_hero.m_special_bullets [i].m_Free==0)
            {
                painter.drawPixmap(m_hero.m_special_bullets[i].m_x,m_hero.m_special_bullets[i].m_y,m_hero.m_special_bullets[i].m_Bullet);
            }

    }
    //绘制第二种特殊子弹
    for(int i=0;i<BULL_NUM3;i++)
    {
            if(m_hero.m_special_bullets2[i].m_Free==0)
            {
                painter.drawPixmap(m_hero.m_special_bullets2[i].m_x,m_hero.m_special_bullets2[i].m_y,m_hero.m_special_bullets2[i].m_Bullet);
            }
    }
    //绘制第三种特殊子弹
    for(int i=0;i<BULL_NUM3;i++)
    {
        if(m_hero.m_special_bullets3[i].m_Free==0)
        {
            painter.drawPixmap(m_hero.m_special_bullets3[i].m_x,m_hero.m_special_bullets3[i].m_y,m_hero.m_special_bullets3[i].m_Bullet);
        }
    }

    //绘制升级图标

    if(m_UpAdds.m_Free==0)
    {
        painter.drawPixmap(m_UpAdds.m_x,m_UpAdds.m_y, m_UpAdds.m_upadd);
    }


    //绘制回血图标

    if(m_BackBloods.m_Free==0)
    {
        painter.drawPixmap(m_BackBloods.m_x,m_BackBloods.m_y, m_BackBloods.m_Back_Blood);
    }

    //绘制护盾图标

    if(m_Defends.m_Free==0)
    {
        painter.drawPixmap(m_Defends.m_x,m_Defends.m_y, m_Defends.m_Defend);
    }


    //绘制金币
    for(int i=0;i<GOLD_NUM;i++)
    {
        if(m_golds[i].m_Free==0)
        {
            painter.drawPixmap(m_golds[i].m_x,m_golds[i].m_y,m_golds[i].m_gold);

        }
    }

    //绘制僚机子弹
    for(int i=0;i<WING_BULLET_NUM;i++)
    {
        if(m_Wing_left.m_bullets[i].m_Free==0)
        {
           painter.drawPixmap(m_Wing_left.m_bullets[i].m_x,m_Wing_left.m_bullets[i].m_y,m_Wing_left.m_bullets[i].m_Bullet);
        }
    }

    //绘制僚机子弹
    for(int i=0;i<WING_BULLET_NUM;i++)
    {
        if(m_Wing_right.m_bullets[i].m_Free==0)
        {
           painter.drawPixmap(m_Wing_right.m_bullets[i].m_x,m_Wing_right.m_bullets[i].m_y,m_Wing_right.m_bullets[i].m_Bullet);
        }
    }
    //绘制敌机一
    for(int i=0;i<ENEMY01_NUM;i++)
    {
        if(m_Enemy01s[i].m_Free==0)
        {
            painter.drawPixmap(m_Enemy01s[i].m_x,m_Enemy01s[i].m_y, m_Enemy01s[i].m_emeny);
            //填充血条颜色
            QBrush bru(QColor(255,0,0));
            //放置血条
            painter.setBrush(bru);
            //计算血条比例
            float rate=1.0*m_Enemy01s[i].m_Blood/ENEMY01_BLOOD;
            //绘制血条
            painter.drawRect(m_Enemy01s[i].m_x,m_Enemy01s[i].m_y,rate*m_Enemy01s[i].m_Rect.width(),20);
            //绘制敌机子弹
            for(int j=0;j<ENEMY01_BULLET_NUM;j++)
            {
                //如果非空闲，绘制
                if(m_Enemy01s[i].enemy_bullet01s[j].m_Free==0)
                {
                   painter.drawPixmap(m_Enemy01s[i].enemy_bullet01s[j].m_x,m_Enemy01s[i].enemy_bullet01s[j].m_y, m_Enemy01s[i].enemy_bullet01s[j].m_Enemy_Bullet);
                }
            }
        }
    }

    //绘制敌机3
    for(int i=0;i<ENEMY03_NUM;i++)
    {
        if(m_Enemy03s[i].m_Free==0)
        {
            painter.drawPixmap(m_Enemy03s[i].m_x,m_Enemy03s[i].m_y, m_Enemy03s[i].m_emeny);
            //填充血条颜色
            QBrush bru(QColor(255,0,0));
            //放置血条
            painter.setBrush(bru);
            //计算血条比例
            float rate=1.0*m_Enemy03s[i].m_Blood/ENEMY03_BLOOD;
            //绘制血条
            painter.drawRect(m_Enemy03s[i].m_x,m_Enemy03s[i].m_y,rate*(m_Enemy03s[i].m_Rect.width()-100),10);

        }
    }




    //绘制boss1
    if(m_Boss01.m_Free==0)
    {
        painter.drawPixmap(m_Boss01.m_x,m_Boss01.m_y,m_Boss01.m_Boss);
        //填充血条颜色
        QBrush bru(QColor(160,32,240));

        //放置血条
        painter.setBrush(bru);
        //计算血条比例
        float rate=1.0*m_Boss01.m_Blood/BOSS01_BLOOD;

        //绘制血条
        painter.drawRect(m_Boss01.m_x,m_Boss01.m_y,rate*m_Boss01.m_Rect.width(),20);
        //绘制子弹一
        for(int i=0;i<BOSS01_BULLET_NUM;i++)
        {
            if(m_Boss01.Boss_Bullet01s[i].m_Free==0)
            {
                painter.drawPixmap(m_Boss01.Boss_Bullet01s[i].m_x,m_Boss01.Boss_Bullet01s[i].m_y,m_Boss01.Boss_Bullet01s[i].m_Enemy_Bullet);
            }
        }
        //绘制子弹二
        for(int i=0;i<BOSS01_BULLET_NUM;i++)
        {
            if(m_Boss01.Boss_Bullet02s[i].m_Free==0)
            {
                painter.drawPixmap(m_Boss01.Boss_Bullet02s[i].m_x,m_Boss01.Boss_Bullet02s[i].m_y,m_Boss01.Boss_Bullet02s[i].m_Enemy_Bullet);
            }
        }
        //绘制子弹三
        for(int i=0;i<BOSS01_BULLET_NUM;i++)
        {
            if(m_Boss01.Boss_Bullet03s[i].m_Free==0)
            {
                painter.drawPixmap(m_Boss01.Boss_Bullet03s[i].m_x,m_Boss01.Boss_Bullet03s[i].m_y,m_Boss01.Boss_Bullet03s[i].m_Enemy_Bullet);
            }
        }
        //绘制子弹四
        for(int i=0;i<BOSS01_BULLET_NUM;i++)
        {
            if(m_Boss01.Boss_Bullet04s[i].m_Free==0)
            {
                painter.drawPixmap(m_Boss01.Boss_Bullet04s[i].m_x,m_Boss01.Boss_Bullet04s[i].m_y,m_Boss01.Boss_Bullet04s[i].m_Enemy_Bullet);
            }
        }
    }

    //绘制爆炸
    for(int i=0;i<BOMB_NUM;i++)
    {
        if(m_bombs[i].m_Free==0)
        {
           painter.drawPixmap(m_bombs[i].m_x,m_bombs[i].m_y,m_bombs[i].m_PixArr[m_bombs[i].m_index]);

        }
    }


}
//鼠标事件
void Playscene::mouseMoveEvent(QMouseEvent *event)
{
    int x=event->x()-m_hero.m_Plane.width()*0.5;
     int y=event->y()-m_hero.m_Plane.height()*0.5;

     //边界检测
     if(x<=0)
     {
         x=0;
     }
     if(x>=GAME_WIDTH-m_hero.m_Rect.width())
     {
         x=GAME_WIDTH-m_hero.m_Rect.width();
     }
     if(y<=0)
     {
         y=0;
     }
     if(y>=GAME_HEIGHT-m_hero.m_Rect.height())
     {
         y=GAME_HEIGHT-m_hero.m_Rect.height();
     }
     m_hero.setPOsition(x,y);
     m_Wing_left.setPOsition(x-60,y+20);
     m_Wing_right.setPOsition(x+130,y+20);
}

//增加子弹出场
void Playscene::Upaddscence()
{
    m_Back_Blood_Recorder++;
    if(m_Back_Blood_Recorder<UPGRADE_INTERVAL*3)
    {
        return;
    }
    m_Back_Blood_Recorder=0;
        //如果是空闲图标出场
        if(m_UpAdds.m_Free)
        {
            m_UpAdds.m_Free=0;
            //坐标
            m_UpAdds.m_x=rand()%(GAME_WIDTH-m_UpAdds.m_Rect.width());
            m_UpAdds.m_y=-m_UpAdds.m_Rect.height();
        }

}
//回血图标出场
void Playscene::Back_Blood_scence()
{
    m_UpAdd_Recorder++;
    if(m_UpAdd_Recorder<UPGRADE_INTERVAL*2)
    {
        return;
    }

    m_UpAdd_Recorder=0;

    //如果是空闲图标出场
    if(m_BackBloods.m_Free)
    {
        m_BackBloods.m_Free=0;
        //坐标
        m_BackBloods.m_x=rand()%(GAME_WIDTH-m_BackBloods.m_Rect.width());
        m_BackBloods.m_y=-m_BackBloods.m_Rect.height();

    }

}
//护盾图标出场
void Playscene::Defend_scence()
{
    m_Defend_Recorder++;
    if(m_Defend_Recorder<UPGRADE_INTERVAL)
    {
        return;
    }

    m_Defend_Recorder=0;

    //如果是空闲图标出场
    if(m_Defends.m_Free)
    {
        m_Defends.m_Free=0;
        //坐标
        m_Defends.m_x=rand()%(GAME_WIDTH-m_Defends.m_Rect.width());
        m_Defends.m_y=-m_Defends.m_Rect.height();

    }

}
//金币出场
void Playscene::Gold_Scene()
{
   Gold_Recorder++;
    if(Gold_Recorder<GOLD_INTERVAL)
    {
        return;
    }

    Gold_Recorder=0;

    for(int i=0;i<GOLD_NUM;i++)
    {
        //如果是空闲图标出场
        if(m_golds[i].m_Free)
        {
            m_golds[i].m_Free=0;
            //坐标
            m_golds[i].m_x=rand()%(GAME_WIDTH-m_Defends.m_Rect.width());
            m_golds[i].m_y=-m_Defends.m_Rect.height();

        }
    }


}
//碰撞检测
void Playscene::collisionDetection()
{

    //升级图标的碰撞检测,如果是空闲的图标，执行下一次循环
    if(m_UpAdds.m_Free==0)
    {
        //如果升级图标和飞机相交，升级
        if(m_UpAdds.m_Rect.intersects(m_hero.m_Rect))
        {
            //播放音效
            up_music->play();

            m_UpAdds.m_Free=1;
            m_hero.AddNum++;
            this->m_hero.m_HERO_Blue+=30;
            if(m_hero.m_HERO_Blue>=m_blue_num)
            {
                m_hero.m_HERO_Blue=m_blue_num;
            }
            if(m_hero.AddNum>=3)
            {
                m_hero.AddNum=3;
            }
        }

    }

    //回血图标碰撞检测
    if(m_BackBloods.m_Free==0)
    {
        //如果回血图标和飞机相交，升级
        if(m_BackBloods.m_Rect.intersects(m_hero.m_Rect))
        {
            //播放音效
            up_music->play();

            m_BackBloods.m_Free=1;
            m_hero.m_Hero_Blood+=(m_blood_num/2);
            if(m_hero.m_Hero_Blood>=m_blood_num)
            {
                m_hero.m_Hero_Blood=m_blood_num;
            }
        }
    }
    //护盾图标碰撞检测
    if(m_Defends.m_Free==0)
    {
        //如果护盾图标和飞机相交，出现护盾
        if(m_Defends .m_Rect.intersects(m_hero.m_Rect)&&m_hero.m_shield_free)
        {

            //播放音效
            up_music->play();
            m_Defends.m_Free=1;
            m_hero.m_shield_free=0;
            QTimer::singleShot(5000,[=](){
                m_hero.m_shield_free=1;
            });

        }


    }

    //金币碰撞
    for(int i=0;i<GOLD_NUM;i++)
    {
        if(m_golds[i].m_Free==0)
        {
            if(m_golds[i].m_Rect.intersects(m_hero.m_Rect))
            {
                m_golds[i].m_Free=1;
                emit(gold_add());
            }
        }
    }


    //敌机1的碰撞检测：  遍历所有非空闲敌机一
    for(int i=0;i<ENEMY01_NUM;i++)
    {
        //如果是空闲敌机，跳过
        if(m_Enemy01s[i].m_Free)
        {
            continue;
        }
        //敌机与子弹的碰撞：遍历所有非空闲子弹
        for(int j=0;j<BULL_NUM;j++)
        {
            if(m_hero.m_bullets1[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Enemy01s[i].m_Rect.intersects(m_hero.m_bullets1[j].m_rect))
            {
                // qDebug()<<m_Enemy01s[i].m_Blood<<endl;
                m_Enemy01s[i].m_Blood-=m_hero.m_Hurt;
                m_hero.m_bullets1[j].m_Free=1;

            }

        }
        //敌机与第二行子弹相交
        for(int j=0;j<BULL_NUM;j++)
        {
            if(m_hero.m_bullets2[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Enemy01s[i].m_Rect.intersects(m_hero.m_bullets2[j].m_rect))
            {
                // qDebug()<<m_Enemy01s[i].m_Blood<<endl;
                m_Enemy01s[i].m_Blood-=m_hero.m_Hurt;
                m_hero.m_bullets2[j].m_Free=1;
            }
        }
        //敌机与第三行子弹相交
        for(int j=0;j<BULL_NUM;j++)
        {
            if(m_hero.m_bullets3[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Enemy01s[i].m_Rect.intersects(m_hero.m_bullets3[j].m_rect))
            {
                // qDebug()<<m_Enemy01s[i].m_Blood<<endl;
                m_Enemy01s[i].m_Blood-=m_hero.m_Hurt;
                m_hero.m_bullets3[j].m_Free=1;
            }
        }

        //敌机与特殊子弹相交
        for(int j=0;j<BULL_NUM2;j++)
        {
            if(m_hero.m_special_bullets[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Enemy01s[i].m_Rect.intersects(m_hero.m_special_bullets[j].m_rect))
            {
                // qDebug()<<m_Enemy01s[i].m_Blood<<endl;
                m_Enemy01s[i].m_Blood-=4;
                m_hero.m_special_bullets[j].m_Free=1;
                m_hero.m_special_bullets[j].t=GAME_HEIGHT;
            }
        }
        //敌机与特殊子弹2相交
        for(int j=0;j<BULL_NUM3;j++)
        {
            if(m_hero.m_special_bullets2[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Enemy01s[i].m_Rect.intersects(m_hero.m_special_bullets2[j].m_rect))
            {
                // qDebug()<<m_Enemy01s[i].m_Blood<<endl;
                m_Enemy01s[i].m_Blood-=4;
                m_hero.m_special_bullets2[j].m_Free=1;
                m_hero.m_special_bullets2[j].t2=GAME_HEIGHT;
            }
        }

        //敌机与特殊子弹3相交
        for(int j=0;j<BULL_NUM3;j++)
        {
            if(m_hero.m_special_bullets3[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Enemy01s[i].m_Rect.intersects(m_hero.m_special_bullets3[j].m_rect))
            {
                // qDebug()<<m_Enemy01s[i].m_Blood<<endl;
                m_Enemy01s[i].m_Blood-=4;
                m_hero.m_special_bullets3[j].m_Free=1;
                m_hero.m_special_bullets3[j].t3=GAME_HEIGHT;
            }
        }

        //敌机与僚机子弹的碰撞：遍历所有非空闲子弹
        for(int j=0;j<WING_BULLET_NUM;j++)
        {
            if(m_Wing_left.m_bullets[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Enemy01s[i].m_Rect.intersects(m_Wing_left.m_bullets[j].m_rect))
            {
                // qDebug()<<m_Enemy01s[i].m_Blood<<endl;
                m_Enemy01s[i].m_Blood-=Wing_Hurt;
                m_Wing_left.m_bullets[j].m_Free=1;

            }

        }

        for(int j=0;j<WING_BULLET_NUM;j++)
        {
            if(m_Wing_right.m_bullets[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Enemy01s[i].m_Rect.intersects(m_Wing_right.m_bullets[j].m_rect))
            {
                // qDebug()<<m_Enemy01s[i].m_Blood<<endl;
                m_Enemy01s[i].m_Blood-=Wing_Hurt;
                m_Wing_right.m_bullets[j].m_Free=1;

            }

        }
        //敌机与战机的碰撞：如果和战机相交，
        if(m_Enemy01s[i].m_Rect.intersects(m_hero.m_Rect))
        {
            //m_timer.stop();
            qDebug()<<m_hero.m_Hero_Blood<<endl;
            if(m_hero.m_shield_free)//如果护盾未出场，战机血量减少
            {
                m_hero.m_Hero_Blood--;
            }
            m_Enemy01s[i].m_Blood--;
        }

        //如果敌机血量小于0，爆炸
        if(m_Enemy01s[i].m_Blood<=0)
        {
            //重置敌机状态
            m_Enemy01s[i].m_Free=1;
            m_Enemy01s[i].m_Blood=ENEMY01_BLOOD;
            //敌机子弹消失
            for(int k=0;k<ENEMY01_BULLET_NUM;k++)
            {
                m_Enemy01s[i].enemy_bullet01s[k].m_Free=1;
            }
            //播放爆炸效果
            for(int k=0;k<BOMB_NUM;k++)
            {
                if(m_bombs[k].m_Free)
                {
                    //空闲的爆炸 播放
                    m_bombs[k].m_Free=0;
                    //更新爆炸坐标
                    m_bombs[k].m_x=m_Enemy01s[i].m_x;
                    m_bombs[k].m_y=m_Enemy01s[i].m_y;
                    break;
                }
            }
            emit(explosion());
            //播放音效
            bomb_music01->play();
        }

        //战机与敌机子弹的碰撞：
        for(int m=0;m<ENEMY01_BULLET_NUM;m++)
        {
            if(m_Enemy01s[i].enemy_bullet01s[m].m_Free)
            {
                continue;
            }
            if(m_Enemy01s[i].enemy_bullet01s[m].m_rect.intersects(m_hero.m_Rect))
            {
                qDebug()<<m_hero.m_Hero_Blood<<endl;

                if(m_hero.m_shield_free)
                {
                    m_hero.m_Hero_Blood-=10;
                }

                m_Enemy01s[i].enemy_bullet01s[m].m_Free=1;
            }
        }

    }

    //敌机3的碰撞检测：  遍历所有非空闲敌机一
    for(int i=0;i<ENEMY03_NUM;i++)
    {
        //如果是空闲敌机，跳过
        if(m_Enemy03s[i].m_Free)
        {
            continue;
        }
        //敌机与子弹的碰撞：遍历所有非空闲子弹
        for(int j=0;j<BULL_NUM;j++)
        {
            if(m_hero.m_bullets1[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Enemy03s[i].m_Rect.intersects(m_hero.m_bullets1[j].m_rect))
            {
                // qDebug()<<m_Enemy03s[i].m_Blood<<endl;
                m_Enemy03s[i].m_Blood-=m_hero.m_Hurt;
                m_hero.m_bullets1[j].m_Free=1;

            }

        }
        //敌机与第二行子弹相交
        for(int j=0;j<BULL_NUM;j++)
        {
            if(m_hero.m_bullets2[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Enemy03s[i].m_Rect.intersects(m_hero.m_bullets2[j].m_rect))
            {
                // qDebug()<<m_Enemy03s[i].m_Blood<<endl;
                m_Enemy03s[i].m_Blood-=m_hero.m_Hurt;
                m_hero.m_bullets2[j].m_Free=1;
            }
        }
        //敌机与第三行子弹相交
        for(int j=0;j<BULL_NUM;j++)
        {
            if(m_hero.m_bullets3[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Enemy03s[i].m_Rect.intersects(m_hero.m_bullets3[j].m_rect))
            {
                // qDebug()<<m_Enemy03s[i].m_Blood<<endl;
                m_Enemy03s[i].m_Blood-=m_hero.m_Hurt;
                m_hero.m_bullets3[j].m_Free=1;
            }
        }

        //敌机与特殊子弹相交
        for(int j=0;j<BULL_NUM2;j++)
        {
            if(m_hero.m_special_bullets[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Enemy03s[i].m_Rect.intersects(m_hero.m_special_bullets[j].m_rect))
            {
                // qDebug()<<m_Enemy03s[i].m_Blood<<endl;
                m_Enemy03s[i].m_Blood-=4;
                m_hero.m_special_bullets[j].m_Free=1;
                m_hero.m_special_bullets[j].t=GAME_HEIGHT;
            }
        }
        //敌机与特殊子弹2相交
        for(int j=0;j<BULL_NUM3;j++)
        {
            if(m_hero.m_special_bullets2[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Enemy03s[i].m_Rect.intersects(m_hero.m_special_bullets2[j].m_rect))
            {
                // qDebug()<<m_Enemy03s[i].m_Blood<<endl;
                m_Enemy03s[i].m_Blood-=4;
                m_hero.m_special_bullets2[j].m_Free=1;
                m_hero.m_special_bullets2[j].t2=GAME_HEIGHT;
            }
        }

        //敌机与特殊子弹3相交
        for(int j=0;j<BULL_NUM3;j++)
        {
            if(m_hero.m_special_bullets3[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Enemy03s[i].m_Rect.intersects(m_hero.m_special_bullets3[j].m_rect))
            {
                // qDebug()<<m_Enemy03s[i].m_Blood<<endl;
                m_Enemy03s[i].m_Blood-=4;
                m_hero.m_special_bullets3[j].m_Free=1;
                m_hero.m_special_bullets3[j].t3=GAME_HEIGHT;
            }
        }

        //敌机与僚机子弹相交
        for(int j=0;j<WING_BULLET_NUM;j++)
        {
            if(m_Wing_left.m_bullets[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Enemy03s[i].m_Rect.intersects(m_Wing_left.m_bullets[j].m_rect))
            {
                // qDebug()<<m_Enemy01s[i].m_Blood<<endl;
                m_Enemy03s[i].m_Blood-=Wing_Hurt;
                m_Wing_left.m_bullets[j].m_Free=1;

            }

        }
        for(int j=0;j<WING_BULLET_NUM;j++)
        {
            if(m_Wing_right.m_bullets[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Enemy03s[i].m_Rect.intersects(m_Wing_right.m_bullets[j].m_rect))
            {
                // qDebug()<<m_Enemy01s[i].m_Blood<<endl;
                m_Enemy03s[i].m_Blood-=Wing_Hurt;
                m_Wing_right.m_bullets[j].m_Free=1;

            }

        }
        //敌机与战机的碰撞：如果和战机相交，
        if(m_Enemy03s[i].m_Rect.intersects(m_hero.m_Rect))
        {
            //m_timer.stop();
            qDebug()<<m_hero.m_Hero_Blood<<endl;
            if(m_hero.m_shield_free)//如果护盾未出场，战机血量减少
            {
                m_hero.m_Hero_Blood--;
            }
            m_Enemy03s[i].m_Blood--;
        }

        //如果敌机血量小于0，爆炸
        if(m_Enemy03s[i].m_Blood<=0)
        {
            //重置敌机状态
            m_Enemy03s[i].m_Free=1;
            m_Enemy03s[i].m_Blood=ENEMY03_BLOOD;

            //播放爆炸效果
            for(int k=0;k<BOMB_NUM;k++)
            {
                if(m_bombs[k].m_Free)
                {
                    //空闲的爆炸 播放
                    m_bombs[k].m_Free=0;
                    //更新爆炸坐标
                    m_bombs[k].m_x=m_Enemy03s[i].m_x;
                    m_bombs[k].m_y=m_Enemy03s[i].m_y;
                    break;
                }
            }
            emit(explosion());
            bomb_music01->play();
        }

    }


    //boss与战机子弹的碰撞
    if(m_Boss01.m_Free==0)
    {


        for(int j=0;j<BULL_NUM;j++)
        {
            if(m_hero.m_bullets1[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Boss01.m_Rect.intersects(m_hero.m_bullets1[j].m_rect))
            {
                qDebug()<<"boss:"<<m_Boss01.m_Blood<<endl;
                m_Boss01.m_Blood-=m_hero.m_Hurt;
                m_hero.m_bullets1[j].m_Free=1;

            }

        }
        for(int j=0;j<BULL_NUM;j++)
        {
            if(m_hero.m_bullets3[j].m_Free)
            {
                continue;
            }
            if(m_Boss01.m_Rect.intersects(m_hero.m_bullets3[j].m_rect))
            {
                //qDebug()<<"boss:"<<m_Boss01.m_Blood<<endl;
                m_Boss01.m_Blood-=m_hero.m_Hurt;
                m_hero.m_bullets3[j].m_Free=1;
            }
        }
        for(int j=0;j<BULL_NUM;j++)
        {
            if(m_hero.m_bullets2[j].m_Free)
            {
                continue;
            }

            if(m_Boss01.m_Rect.intersects(m_hero.m_bullets2[j].m_rect))
            {
                //qDebug()<<"boss:"<<m_Boss01.m_Blood<<endl;
                m_Boss01.m_Blood-=m_hero.m_Hurt;
                m_hero.m_bullets2[j].m_Free=1;

            }

        }
        for(int j=0;j<BULL_NUM2;j++)
        {
            if(m_hero.m_special_bullets[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Boss01.m_Rect.intersects(m_hero.m_special_bullets[j].m_rect))
            {
                // qDebug()<<m_Enemy01s[i].m_Blood<<endl;
                m_Boss01.m_Blood-=4;
                m_hero.m_special_bullets[j].m_Free=1;
                m_hero.m_special_bullets[j].t=GAME_HEIGHT;
            }
        }

        //与特殊子弹2
        for(int j=0;j<BULL_NUM3;j++)
        {
            if(m_hero.m_special_bullets2[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Boss01.m_Rect.intersects(m_hero.m_special_bullets2[j].m_rect))
            {
                // qDebug()<<m_Enemy01s[i].m_Blood<<endl;
                m_Boss01.m_Blood-=4;
                m_hero.m_special_bullets2[j].m_Free=1;
                m_hero.m_special_bullets2[j].t2=GAME_HEIGHT;
            }
        }
        //与特殊子弹3
        for(int j=0;j<BULL_NUM3;j++)
        {
            if(m_hero.m_special_bullets3[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Boss01.m_Rect.intersects(m_hero.m_special_bullets3[j].m_rect))
            {
                // qDebug()<<m_Enemy01s[i].m_Blood<<endl;
                m_Boss01.m_Blood-=4;
                m_hero.m_special_bullets3[j].m_Free=1;
                m_hero.m_special_bullets3[j].t3=GAME_HEIGHT;
            }
        }

        //敌机与僚机子弹的碰撞：遍历所有非空闲子弹
        for(int j=0;j<WING_BULLET_NUM;j++)
        {
            if(m_Wing_left.m_bullets[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Boss01.m_Rect.intersects(m_Wing_left.m_bullets[j].m_rect))
            {
                // qDebug()<<m_Enemy01s[i].m_Blood<<endl;
                m_Boss01.m_Blood-=Wing_Hurt;
                m_Wing_left.m_bullets[j].m_Free=1;

            }

        }
        for(int j=0;j<WING_BULLET_NUM;j++)
        {
            if(m_Wing_right.m_bullets[j].m_Free)
            {
                continue;
            }
            //如果和子弹相交，发生碰撞
            if(m_Boss01.m_Rect.intersects(m_Wing_right.m_bullets[j].m_rect))
            {
                // qDebug()<<m_Enemy01s[i].m_Blood<<endl;
                m_Boss01.m_Blood-=Wing_Hurt;
                m_Wing_right.m_bullets[j].m_Free=1;

            }

        }


    }


    //boss爆炸
    if(m_Boss01.m_Blood<=0)
    {

        //播放爆炸效果
        for(int s=0;s<BOMB_NUM;s++)
        {
            if(m_bombs[s].m_Free)
            {
                //空闲的爆炸 播放
                m_bombs[s].m_Free=0;
                //更新爆炸坐标
                m_bombs[s].m_x=m_Boss01.m_x+50;
                m_bombs[s].m_y=m_Boss01.m_y;
                break;
            }
        }
        for(int s=0;s<BOMB_NUM;s++)
        {
            if(m_bombs[s].m_Free)
            {
                //空闲的爆炸 播放
                m_bombs[s].m_Free=0;
                //更新爆炸坐标
                m_bombs[s].m_x=m_Boss01.m_x+250;
                m_bombs[s].m_y=m_Boss01.m_y;
                break;
            }
        }
        for(int s=0;s<BOMB_NUM;s++)
        {
            if(m_bombs[s].m_Free)
            {
                //空闲的爆炸 播放
                m_bombs[s].m_Free=0;
                //更新爆炸坐标
                m_bombs[s].m_x=m_Boss01.m_x+150;
                m_bombs[s].m_y=m_Boss01.m_y+200;
                break;
            }
        }

       //释放爆炸信号
        emit(boss_explosion());
        m_Boss01.m_Free=1;
        m_Boss01.m_Blood=BOSS01_BLOOD;
        //播放爆炸音效
        bomb_music02->play();


        //所有子弹消失
        for(int k=0;k<BOSS01_BULLET_NUM;k++)
        {
            m_Boss01.Boss_Bullet01s[k].m_Free=1;
            m_Boss01.Boss_Bullet02s[k].m_Free=1;
            m_Boss01.Boss_Bullet03s[k].m_Free=1;
            m_Boss01.Boss_Bullet04s[k].m_Free=1;

        }

    }


    //战机与boss子弹的碰撞
    //第一种
    for(int k=0;k<BOSS01_BULLET_NUM;k++)
    {
        if(m_Boss01.Boss_Bullet01s[k].m_Free)
        {
            continue;
        }
        if(m_Boss01.Boss_Bullet01s[k].m_rect.intersects(m_hero.m_Rect))
        {
            qDebug()<<m_hero.m_Hero_Blood<<endl;
            if(m_hero.m_shield_free)
            {
                m_hero.m_Hero_Blood-=BOSS01_BULLET01_HURT;
            }         
            m_Boss01.Boss_Bullet01s[k].m_Free=1;
        }
    }
    //第二种
    for(int k=0;k<BOSS01_BULLET_NUM;k++)
    {
        if(m_Boss01.Boss_Bullet02s[k].m_Free)
        {
            continue;
        }
        if(m_Boss01.Boss_Bullet02s[k].m_rect.intersects(m_hero.m_Rect))
        {
            qDebug()<<m_hero.m_Hero_Blood<<endl;
            if(m_hero.m_shield_free)
            {
                m_hero.m_Hero_Blood-=BOSS01_BULLET02_HURT;
            }

            m_Boss01.Boss_Bullet02s[k].m_Free=1;
        }
    }
    //第三种
    for(int k=0;k<BOSS01_BULLET_NUM;k++)
    {
        if(m_Boss01.Boss_Bullet03s[k].m_Free)
        {
            continue;
        }
        if(m_Boss01.Boss_Bullet03s[k].m_rect.intersects(m_hero.m_Rect))
        {
            qDebug()<<m_hero.m_Hero_Blood<<endl;
            if(m_hero.m_shield_free)
            {
                m_hero.m_Hero_Blood-=BOSS01_BULLET03_HURT;
            }

            m_Boss01.Boss_Bullet03s[k].m_Free=1;
        }
    }
    //第四种
    for(int k=0;k<BOSS01_BULLET_NUM;k++)
    {
        if(m_Boss01.Boss_Bullet04s[k].m_Free)
        {
            continue;
        }
        if(m_Boss01.Boss_Bullet04s[k].m_rect.intersects(m_hero.m_Rect))
        {
            qDebug()<<m_hero.m_Hero_Blood<<endl;
            if(m_hero.m_shield_free)
            {
                m_hero.m_Hero_Blood-=BOSS01_BULLET04_HURT;
            }

            m_Boss01.Boss_Bullet04s[k].m_Free=1;
        }
    }

    //游戏结束
   if(m_hero.m_Hero_Blood<=0)
    {
        m_timer.stop();
        //将结束图片移动下来
        QPropertyAnimation*animation=new QPropertyAnimation(overlable,"geometry");
        //设置时间间隔
        animation->setDuration(1000);
        //设置开始位置
        animation->setStartValue(QRect(overlable->x(),overlable->y(),overlable->width(),overlable->height()));
        //结束位置
        animation->setEndValue(QRect(overlable->x(),overlable->y()+550,overlable->width(),overlable->height()));
        //曲线
        animation->setEasingCurve(QEasingCurve::OutBounce);
        //执行
        animation->start();

        //播放音效
        back_music->stop();
        over_music->play();

    }

}
//敌机出场
void Playscene::Enemy01scence()
{
    //敌机一
    m_Enemy01_Recorder++;
    if(m_Enemy01_Recorder<ENEMY01_INTERVAL)
    {
        return;
    }
    m_Enemy01_Recorder=0;
    for(int i=0;i<ENEMY01_NUM;i++)
    {
        //如果是空闲敌机出场
        if(m_Enemy01s[i].m_Free)
        {
            m_Enemy01s[i].m_Free=0;
            //坐标
            m_Enemy01s[i].m_x=rand()%(GAME_WIDTH-m_Enemy01s[i].m_Rect.width());
            m_Enemy01s[i].m_y=-m_Enemy01s[i].m_Rect.height();
            break;
        }
    }


}
//敌机3
void Playscene::Enemy03scence()
{
    //敌机一
    m_Enemy03_Recorder++;
    if(m_Enemy03_Recorder<ENEMY03_INTERVAL)
    {
        return;
    }
    m_Enemy03_Recorder=0;
    for(int i=0;i<ENEMY03_NUM;i++)
    {
        //如果是空闲敌机出场
        if(m_Enemy03s[i].m_Free)
        {
            m_Enemy03s[i].m_Free=0;
            //坐标
            m_Enemy03s[i].m_y=300;//rand()%(GAME_WIDTH-m_Enemy03s[i].m_Rect.width()+200);
            m_Enemy03s[i].m_x=-m_Enemy03s[i].m_Rect.height()-100;
            break;
        }
    }

}
//boss出场
void Playscene::Boss_scence()
{

    if(m_Boss01.m_Free==1&&(num==50||num==200||num==500))
    {
        //warnning出现
        warnlabel->move(300,300);
        //播放音效
        alarm_music->play();
        //boss延时出现，warning消失

        QTimer::singleShot(3000,this,[=](){

            this->m_Boss01.m_Free=0;
            this->m_Boss01.m_y=-500;
            warnlabel->move(500,-500);
        });

    }
}
